package com.highspeed.bdk.controller.physical;

import com.bianmaba.spring.data.jpa.domain.Result;
import com.bianmaba.spring.mvc.method.support.annotations.JSON;
import com.highspeed.bdk.bean.entity.physical.Board;
import com.highspeed.bdk.bean.entity.physical.Cpu;
import com.highspeed.bdk.controller.base.BdkCrudController;
import com.highspeed.bdk.service.physical.IBoardService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = {"board"}, method = RequestMethod.POST)
@Api(tags = "板卡")
public class BoardController extends BdkCrudController<Board, Integer> {
    @Autowired
    private IBoardService boardService;

    @Override
    protected IBoardService getService() {
        return boardService;
    }

    @ApiOperation(value = "保存整个主板配置，在必要时可以调用此函数保存单个主板配置", notes = "参数为JSON数据;<br/>" +
            "主板信息中必须包含：machineBox.id属性，不然不会与相关机箱关联（如果已经关联的则会断开）;<br/>" +
            "数据中的链路信息不会被保存,需要单独调用physical_link\\save来保存;")
    @JSON
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @Override
    public Result save(@RequestBody @ApiParam(name = "entity") Board entity) {
        return super.save(entity);
    }


    @JSON(excludeProperties = {"data.*\\.cpus", "data.*\\.machineBox"})
    @ApiOperation(
            value = "将主板移到另一个机箱上",
            notes = "返回数据中的success为true表示删除成功"
    )
    @RequestMapping(
            value = {"/move"},
            method = {RequestMethod.POST}
    )
    @ApiImplicitParams({
            @ApiImplicitParam(name = "boardId", value = "", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "machineBoxId", value = "", dataType = "int", paramType = "query")}
    )
    public Result save(Integer boardId, Integer machineBoxId) {
        Board board = getService().move(boardId, machineBoxId);
        return new Result(true, null, board);
    }
}
